package com.maple.common.controller;

import com.maple.common.exception.BusinessException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.Objects;

/**
 * <p></p>
 *
 * @author maple
 */
@RestController
@RequestMapping("exception")
public class ExceptionTestController {

    static class Request {
        @NotBlank
        public String param;
    }

    @PostMapping("show")
    public String checkPassword(@Validated @RequestBody Request request) {

        if (Objects.equals(request.param, "maple")) {
            throw new BusinessException("传参字符串为maple");
        }

        return "当前参数，param: " + request.param;
    }
}
